package com.ambercrm.business.main;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebSettings;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.ambercrm.R;
import com.ambercrm.base.BaseTitleActivity;
import com.ambercrm.base.MyApplication;
import com.ambercrm.beans.CommonClass;
import com.ambercrm.business.bean.UploadImageBean;
import com.ambercrm.business.location.CheckLocationActivity;
import com.ambercrm.business.location.SelectLocationActivity;
import com.ambercrm.business.location.event.SelectLocationResult;
import com.ambercrm.common.Common;
import com.ambercrm.constant.Constant;
import com.ambercrm.constant.UrlConstant;
import com.ambercrm.http.HttpUtils;
import com.ambercrm.push.ExampleUtil;
import com.ambercrm.tools.LogUtils;
import com.ambercrm.tools.ThreadUtils;
import com.ambercrm.tools.ToastUtils;
import com.ambercrm.tools.VibrateHelper;
import com.ambercrm.tools.player.Player;
import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.BridgeWebViewClient;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.smtt.sdk.WebView;
import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumConfig;
import com.yanzhenjie.album.AlbumFile;
import com.yanzhenjie.album.AlbumLoader;
import com.yanzhenjie.album.Filter;
import com.yanzhenjie.kalle.FileBinary;
import com.yanzhenjie.kalle.FormBody;
import com.yanzhenjie.kalle.Kalle;
import com.yanzhenjie.kalle.ProgressBar;
import com.yanzhenjie.kalle.simple.SimpleCallback;
import com.yanzhenjie.kalle.simple.SimpleResponse;

import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends BaseTitleActivity {
    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_main;
    }

    private BridgeWebView mWebView;
    private RelativeLayout myContainer;
    private RelativeLayout messageLayout;
    private ImageView messageImg;
    private RelativeLayout applicationLayout;
    private ImageView applicationImg;
    private RelativeLayout contactLayout;
    private ImageView contactImg;
    private RelativeLayout myLayout;
    private ImageView myImg;
    LinearLayout mBottomToolBar;
    View mBottomLine;
    PowerManager.WakeLock mWakeLock;
    int jumpFlag = -1; // 0拍照， 1相册   2识别名片   3地图选址
    CallBackFunction mCallBackFunction; // 界面跳转的回调函数
    CallBackFunction mLocationCallBackFunction; // 界面跳转的回调函数
    Handler mHandler;

    //声明mlocationClient对象
    public AMapLocationClient mlocationClient;
    //声明mLocationOption对象
    public AMapLocationClientOption mLocationOption = null;
    Gson mGson = null;
    @SuppressLint("InvalidWakeLockTag")
    @Override
    protected void initContentView(View v) {
        mTitleLayout.setVisibility(View.GONE);
        changeStatusColor(R.color.white);
        mHandler = new Handler();
        mGson = new Gson();
        mWebView = v.findViewById(R.id.webview);
        myContainer = v.findViewById(R.id.my_container);
        messageLayout = v.findViewById(R.id.message_layout);
        messageImg = v.findViewById(R.id.message_img);
        applicationLayout = v.findViewById(R.id.application_layout);
        applicationImg = v.findViewById(R.id.application_img);
        contactLayout = v.findViewById(R.id.contact_layout);
        mBottomToolBar = v.findViewById(R.id.bottom_tool_bar);
        mBottomLine = v.findViewById(R.id.bottom_line);
        contactImg = v.findViewById(R.id.contact_img);
        myLayout = v.findViewById(R.id.my_layout);
        myImg = v.findViewById(R.id.my_img);
        PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
        if (powerManager != null) {
            mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "WakeLock");
        }
        OnButtonClick onButtonClick = new OnButtonClick();
        messageLayout.setOnClickListener(onButtonClick);
        applicationLayout.setOnClickListener(onButtonClick);
        contactLayout.setOnClickListener(onButtonClick);
        myLayout.setOnClickListener(onButtonClick);

        initWebView();

        tabSelect(0);

        // 初始化相册， 设置加载方式， 可以自己实现，用ImageLoader或者用Glide
        Album.initialize(AlbumConfig.newBuilder(this)
                .setAlbumLoader(new MediaLoader())
                .build());

        // 初始化定位
        initLocation();

        registerMessageReceiver();
    }

    private void initLocation() {
        mlocationClient = new AMapLocationClient(this);
        //初始化定位参数
        mLocationOption = new AMapLocationClientOption();
        //设置返回地址信息，默认为true
        mLocationOption.setNeedAddress(true);
        //设置定位监听
        mlocationClient.setLocationListener(new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                if (aMapLocation != null) {
                    double longtitude = aMapLocation.getLongitude();
                    double latitude = aMapLocation.getLatitude();
                    mlocationClient.stopLocation();
                    if (mLocationCallBackFunction != null) {
                        HashMap<String, String> map = new HashMap<>();
                        map.put("longitude", longtitude+"");
                        map.put("latitude", latitude+"");
                        map.put("province", aMapLocation.getProvince());
                        map.put("city", aMapLocation.getCity());
                        map.put("district", aMapLocation.getDistrict());
                        mLocationCallBackFunction.onCallBack(mGson.toJson(map));
                    }
                }
                else {
                    toast("定位失败");
                }
            }
        });
        //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置定位间隔,单位毫秒,默认为2000ms
        mLocationOption.setInterval(2000);
        //设置定位参数
        mlocationClient.setLocationOption(mLocationOption);
        mlocationClient.startLocation();
    }

    class OnButtonClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if (v == messageLayout) {
                tabSelect(0);
            }
            else if (applicationLayout == v) {
                tabSelect(1);
            }
            else if (v == contactLayout) {
                tabSelect(2);
            }
            else if (v == myLayout) {
                tabSelect(3);
            }
        }
    }

    private void tabSelect(int index) {
        if (index == 0) {
            mWebView.setVisibility(View.VISIBLE);
            myContainer.setVisibility(View.GONE);
            messageImg.setImageResource(R.mipmap.message_select_icon);
            applicationImg.setImageResource(R.mipmap.application_icon);
            contactImg.setImageResource(R.mipmap.contact_icon);
            myImg.setImageResource(R.mipmap.my_icon);
            mWebView.loadUrl(UrlConstant.H5BaseUrl + "/#/message");
        }
        else if (index == 1) {
            mWebView.setVisibility(View.VISIBLE);
            myContainer.setVisibility(View.GONE);
            messageImg.setImageResource(R.mipmap.message_icon);
            applicationImg.setImageResource(R.mipmap.application_select_icon);
            contactImg.setImageResource(R.mipmap.contact_icon);
            myImg.setImageResource(R.mipmap.my_icon);
            mWebView.loadUrl(UrlConstant.H5BaseUrl + "/#/application");
        }
        else if (index == 2) {
            mWebView.setVisibility(View.VISIBLE);
            myContainer.setVisibility(View.GONE);
            messageImg.setImageResource(R.mipmap.message_icon);
            applicationImg.setImageResource(R.mipmap.application_icon);
            contactImg.setImageResource(R.mipmap.contact_select_icon);
            myImg.setImageResource(R.mipmap.my_icon);
            mWebView.loadUrl(UrlConstant.H5BaseUrl + "/#/address-book");
        }
        else if (index == 3) {
            mWebView.setVisibility(View.GONE);
            myContainer.setVisibility(View.VISIBLE);
            messageImg.setImageResource(R.mipmap.message_icon);
            applicationImg.setImageResource(R.mipmap.application_icon);
            contactImg.setImageResource(R.mipmap.contact_icon);
            myImg.setImageResource(R.mipmap.my_select_icon);
        }
    }

    private void initWebView() {
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mWebView.getSettings().setAppCacheEnabled(false);
        mWebView.getSettings().setAllowContentAccess(true);
        mWebView.getSettings().setAllowFileAccess(true);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.requestFocus();
//        mWebView.getSettings().setSupportZoom(false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mWebView.setWebContentsDebuggingEnabled(true);
        }
        mWebView.setWebViewClient(new MyWebViewClient(mWebView));
        try {
            registerJsMethod();
        }
        catch (Exception e) {

        }
    }

    public class MyWebViewClient extends BridgeWebViewClient {

        public MyWebViewClient(BridgeWebView webView) {
            super(webView);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    javaCallJs();
                }
            }, 500);

            LogUtils.showLog("onPageFish()");
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            LogUtils.showLog("onReceivedError()");
        }
    }

    String mJson = "";
    // 给web端注册方法，供他调用
    private void registerJsMethod() {
        mWebView.registerHandler("getToken", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                function.onCallBack(sp.getValue(Constant.sp_Token));
            }
        });

        mWebView.registerHandler("HttpPost", new BridgeHandler() {
            @Override
            public void handler(final String data, final CallBackFunction function) {
                ThreadUtils.newThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            JSONObject obj = new JSONObject(data);
                            String url = obj.getString("url");
                            JSONObject dataObj = obj.getJSONObject("data");
                            mJson = HttpUtils.httpPostSync(url, dataObj.toString());
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    function.onCallBack(mJson);
                                }
                            });
                        }
                        catch (Exception e) {

                        }
                    }
                });
            }
        });

        mWebView.registerHandler("CallPhone", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    String phone = obj.getString("phone");
                    callPhone(phone);
                }
                catch (Exception e) {

                }
            }
        });

        mWebView.registerHandler("PlaySound", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    String url = obj.getString("url");
                    String name = obj.getString("name");
                    playMp3(url);
                }
                catch (Exception e) {

                }
            }
        });

        mWebView.registerHandler("Vibrate", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    int time = obj.getInt("during");
                    vibrate(time);
                }
                catch (Exception e) {

                }
            }
        });

        mWebView.registerHandler("SetPasteboard", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    String text = obj.getString("text");
                    saveToClipBoard(text);
                }
                catch (Exception e) {

                }
            }
        });

        // 设置屏幕长亮
        mWebView.registerHandler("KeyScreenOn", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    int keep = obj.getInt("on");
                    if (keep == 1) {
                        mWakeLock.acquire();
                    }
                    else {
                        mWakeLock.release();
                    }
                }
                catch (Exception e) {

                }
            }
        });

        mWebView.registerHandler("ShowView", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    mCallBackFunction = function;
                    LogUtils.showLog("保存回调函数");
                    JSONObject obj = new JSONObject(data);
                    String name = obj.getString("name");
//                  jumpFlag = -1; // 0拍照， 1相册   2识别名片   3地图选址
                    if ("CameraView".equals(name)) { // 拍照页面
                        jumpFlag = 0;
                        Album.camera(mContext) // Camera function.
                                .image() // Take Picture.
                                .onResult(new Action<String>() {
                                    @Override
                                    public void onAction(@NonNull String result) {
                                        LogUtils.showLog("返回地址：" + result);
                                        mUploadCount = 0;
                                        mUploadImageList = new ArrayList<>();
                                        mImagePathList = new ArrayList<>();
                                        mImagePathList.add(result);
                                        uploadFile(result);
                                    }
                                })
                                .onCancel(new Action<String>() {
                                    @Override
                                    public void onAction(@NonNull String result) {
                                        LogUtils.showLog(result);
                                    }
                                })
                                .start();
                    }
                    else if ("PhotoView".equals(name)) { // 相册选择页面
                        jumpFlag = 1;
                        Album.image(mContext) // Image selection.
                                .multipleChoice()
                                .camera(true)
                                .columnCount(4)
                                .selectCount(9)
                                .filterMimeType(new Filter<String>() { // 过滤图片格式，只显示jpg和png的图片
                                    @Override
                                    public boolean filter(String attributes) {
                                        return attributes.contains(".jpg") || attributes.contains(".png");
                                    }
                                }) // 过滤文件格式
                                .afterFilterVisibility(true) // Show the filtered files, but they are not available.
                                .onResult(new Action<ArrayList<AlbumFile>>() {
                                    @Override
                                    public void onAction(@NonNull ArrayList<AlbumFile> result) {
                                        mUploadCount = 0;
                                        mUploadImageList = new ArrayList<>();
                                        mImagePathList = new ArrayList<>();

                                        for (int i = 0; i < result.size(); i++) {
                                            mImagePathList.add(result.get(i).getPath());
                                        }
                                        uploadFile(result.get(0).getPath());
                                    }
                                })
                                .onCancel(new Action<String>() {
                                    @Override
                                    public void onAction(@NonNull String result) {

                                    }
                                })
                                .start();
                    }
                    else if ("CardView".equals(name)) { // 识别名片界面
                        jumpFlag = 2;
                        Album.camera(mContext) // Camera function.
                                .image() // Take Picture.
                                .onResult(new Action<String>() {
                                    @Override
                                    public void onAction(@NonNull String result) {
                                        LogUtils.showLog("返回地址：" + result);
                                    }
                                })
                                .onCancel(new Action<String>() {
                                    @Override
                                    public void onAction(@NonNull String result) {
                                        LogUtils.showLog(result);
                                    }
                                })
                                .start();
                    }
                    else if ("MapSelectView".equals(name)) { // 地图选址界面
                        jumpFlag = 3;
                        startActivity(SelectLocationActivity.class, null, false);
                    }
                }
                catch (Exception e) {

                }
            }
        });

        mWebView.registerHandler("GetLocation", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                mLocationCallBackFunction = function;
                mlocationClient.startLocation();
            }
        });

        mWebView.registerHandler("HideToolBar", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                mBottomToolBar.setVisibility(View.GONE);
                mBottomLine.setVisibility(View.GONE);
            }
        });

        mWebView.registerHandler("ShowToolBar", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                mBottomToolBar.setVisibility(View.VISIBLE);
                mBottomLine.setVisibility(View.VISIBLE);
            }
        });

        mWebView.registerHandler("MapShowView", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                try {
                    JSONObject obj = new JSONObject(data);
                    double longitude = obj.getDouble("longitude");
                    double latitude = obj.getDouble("latitude");
                    Bundle b = new Bundle();
                    b.putDouble("longitude", longitude);
                    b.putDouble("latitude", latitude);
                    startActivity(CheckLocationActivity.class, b, false);
                }
                catch (Exception e) {

                }
            }
        });
    }

    // Java掉js代码
    private void javaCallJs() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            mWebView.clearCache(true);
            ViewParent parent = mWebView.getParent();
            if (parent != null) {
                ((ViewGroup) parent).removeView(mWebView);
            }
            mWebView.stopLoading();
            mWebView.clearHistory();
            mWebView.clearView();
            mWebView.removeAllViews();
            mWebView.destroy();
            mWebView = null;

            mlocationClient.stopLocation();
            mlocationClient = null;
        } catch (Exception e) {

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mWebView.onResume();
        mWebView.resumeTimers();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mWebView.onPause();
        mWebView.pauseTimers();
    }

    @Override
    public void onBackPressed() {
        if (mWebView.canGoBack()) {
            mWebView.goBack();
        }
        else {
            finishActivity();
        }
    }

    public class MediaLoader implements AlbumLoader {
        @Override
        public void load(ImageView imageView, AlbumFile albumFile) {
            load(imageView, albumFile.getPath());
        }

        @Override
        public void load(ImageView imageView, String url) {
            MyApplication.getApplicationInstance().displayImg("file://" + url, imageView);
        }
    }

    public void onEventMainThread(SelectLocationResult event) {
        HashMap<String, String> map = new HashMap<>();
        map.put("longitude", event.getNearAddressBean().getxOffset());
        map.put("latitude", event.getNearAddressBean().getyOffset());
        map.put("province", event.getNearAddressBean().getProvince());
        map.put("city", event.getNearAddressBean().getCity());
        map.put("district", event.getNearAddressBean().getCounty());
        map.put("address", event.getNearAddressBean().getAddress());
        Gson gson = new Gson();
        String json = gson.toJson(map);
        LogUtils.showLog("执行回调" + json);
        mCallBackFunction.onCallBack(json);
    }

    int mUploadCount = 0;
    ArrayList<UploadImageBean> mUploadImageList;
    ArrayList<String> mImagePathList;
    // 上传单个文件
    private void uploadFile(String imagePath) {
        final String token = Common.getInstance().getToken();
        String url = UrlConstant.baseUploadUrl + "/upload/addFiles";
        LogUtils.showLog(url);

        FileBinary fileBinary = new FileBinary(new File(imagePath));
        fileBinary.onProgress(new ProgressBar<FileBinary>() {
            @Override
            public void progress(FileBinary origin, int progress) {
                // 单个文件进度
            }
        });

        FormBody formBody = FormBody.newBuilder()
                .param("sourceName", "bbbb")
                .param("sourceTable", "jingtian")
                .param("objectGroup", "crm")
                .param("resourceUrl", "https://filesdev.ztocwst.com/images")
                .binary("file", fileBinary)
                .build();

        formBody.onProgress(new ProgressBar<FormBody>() {
            @Override
            public void progress(FormBody origin, int progress) {
                // 整体进度
            }
        });
        Kalle.post(url)
                .body(formBody)
                .param("token", token)
                .addHeader("Authorization", token == null ? "" : (token)) // 添加请求头。
                .perform(new SimpleCallback<String>() {
                    @Override
                    public void onResponse(SimpleResponse<String, String> response) {
                        if (response.isSucceed()) {
                            // 整体上传完成的回调
                            LogUtils.showLog("上传完成：" + response.succeed());
                            CommonClass<UploadImageBean> commonClass = mGson.fromJson(response.succeed(), new TypeToken<CommonClass<UploadImageBean>>() {}.getType());

                            if (commonClass.getCode() == 105) {
                                toast(commonClass.getMsg());
                                return;
                            }

                            mUploadImageList.add(commonClass.getResult());
                            mUploadCount++;
                            if (mUploadCount >= mUploadImageList.size()) {
                                HashMap<String, Object> map = new HashMap<>();
                                ArrayList<String> list = new ArrayList<>();
                                for (int i = 0; i < mUploadImageList.size(); i++) {
                                    list.add(mUploadImageList.get(i).getResourceUrl()+"/"+mUploadImageList.get(i).getResourcesId() + "?token=" + token);
                                }
                                map.put("imageUrls", list);
                                mCallBackFunction.onCallBack(mGson.toJson(map));
                            }
                            else {
                                uploadFile(mImagePathList.get(mUploadCount));
                            }
                        } else {
                            ToastUtils.showToast("上传失败：" + response.failed());
                        }
                    }
                });
    }

    // --------------------------------WebView 封装-------------------------------
    // 给h5封装方法

    // 拨打电话
    private void callPhone(String json) {
        try {
            JSONObject obj = new JSONObject(json);
            String phone = obj.getString("phone");
            Intent intent=new Intent();
            intent.setAction(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + phone));
            //开启系统拨号器
            startActivity(intent);
        }
        catch (Exception e) {

        }
    }

    // 播放mp3
    private void playMp3(String mp3Url) {
        Player player = new Player(this);
        player.playUrl(mp3Url);
    }

    // 手机震动
    private void vibrate(int time) {
        VibrateHelper.vibrate(this, new long[] {time}, false);
    }

    private void saveToClipBoard(String str) {
        saveToClipboard(str);
    }


    public void registerMessageReceiver() {
        MessageReceiver mMessageReceiver = new MessageReceiver();
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(MESSAGE_RECEIVED_ACTION);
        LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
    }

    public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
    public static final String KEY_MESSAGE = "message";
    public static final String KEY_EXTRAS = "extras";
    public class MessageReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
                    String messge = intent.getStringExtra(KEY_MESSAGE);
                    String extras = intent.getStringExtra(KEY_EXTRAS);
                    StringBuilder showMsg = new StringBuilder();
                    showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
                    if (!ExampleUtil.isEmpty(extras)) {
                        showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
                    }
                    LogUtils.showLog(showMsg.toString());
                }
            } catch (Exception e){
            }
        }
    }
}

//2019-04-25 13:59:48.032 13704-13704/? D/dongjiejie: getFileDir----/data/user/0/com.manager.carmanager/files
//        2019-04-25 13:59:48.033 13704-13704/? D/dongjiejie: getCacheDir----/data/user/0/com.manager.carmanager/cache
//        2019-04-25 13:59:48.037 13704-13704/? D/dongjiejie: getExternalStorageDirectory---/storage/emulated/0
//        2019-04-25 13:59:48.040 13704-13704/? D/dongjiejie: getExternalFilesDirs0-----/storage/emulated/0/Android/data/com.manager.carmanager/files
//        2019-04-25 13:59:48.042 13704-13704/? D/dongjiejie: getExternalCacheDirs0-----/storage/emulated/0/Android/data/com.manager.carmanager/cache